package model

import (
	"manager/model/entity"
)

type ShareStatus int

const (
	ShareWait ShareStatus = iota + 1
	ShareOk
	ShareRefuse
	ShareExpire
)

type ShareEbikeType int

const (
	ShareTypeUser      ShareEbikeType = iota // 主动分享
	ShareTypeShareUser                       // 被动分享
)

// ShareEbikeCreateRequest 创建现场数据
type ShareEbikeCreateRequest struct {
	UserId int64 `json:"user_id"`

	EbikeId int64 `json:"ebike_id" binding:"required"`

	ShareUserId int64 `json:"share_user_id"`

	Phone string `json:"phone" binding:"required"`

	Name string `json:"name" `

	ShareTime int64 `json:"share_time" binding:"required"`

	Status int `json:"status"`
}

// ShareEbikeUpdateRequest 更新现场数据
type ShareEbikeUpdateRequest struct {
	Id int64 `json:"id"  binding:"required"`

	UserId *int64 `json:"user_id"`

	EbikeId *int64 `json:"ebike_id"`

	ShareUserId *int64 `json:"share_user_id"`

	Phone *string `json:"phone"`

	Name *string `json:"name"`

	ShareTime *int64 `json:"share_time"`

	Status *int `json:"status"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt *int64 `json:"updated_at"`
}

type ShareAllRequest struct {
	Index  int    `json:"index"`
	Size   int    `json:"size"`
	UserId *int64 `json:"user_id"`

	EbikeId *int64 `json:"ebike_id"`

	ShareUserId *int64 `json:"share_user_id"`

	Phone *string `json:"phone"`

	Name *string `json:"name"`

	ShareTime *int64 `json:"share_time"`

	Status *int `json:"status"`

	FilterStatus []int `json:"filter_status"`
}

// ShareEbikeListRequest 列表现场数据
type ShareEbikeListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	Id int64 `json:"id"`

	UserId *int64 `json:"user_id"`

	EbikeId *int64 `json:"ebike_id"`

	BikeIds []int64 `json:"bike_ids"`

	ShareUserId *int64 `json:"share_user_id"`

	Phone *string `json:"phone"`

	Name *string `json:"name"`

	ShareTime *int64 `json:"share_time"`

	Status *int `json:"status"`

	FilterStatus []int `json:"filter_status"`

	Type *int `json:"type" binding:"required"`

	CreatedAt *int64 `json:"created_at"`
}

// ShareEbikeListResponse 列表回包数据
type ShareEbikeListResponse struct {
	Total int               `json:"total"`
	List  []*ShareEbikeInfo `json:"list"`
}

// ShareEbikeListAllResponse 列表回包数据
type ShareEbikeListAllResponse struct {
	Total int          `json:"total"`
	List  []*EbikeList `json:"list"`
}

type EbikeList struct {
	ID            int64             `json:"ID"`
	Name          string            `json:"name"`
	CreatedAt     int64             `json:"created_at"`
	Photo         string            `json:"photo"`
	Count         int64             `json:"count"`
	ShareUserList []*ShareEbikeInfo `gorm:"-" json:"list"`
}

// ShareEbikeInfo 详细数据
type ShareEbikeInfo struct {
	Id int64 `json:"id"`

	UserId int64 `json:"user_id"`

	EbikeId int64 `json:"ebike_id"`

	ShareUserId int64 `json:"share_user_id"`

	Phone string `json:"phone"`

	Name string `json:"name"` //车辆名称

	UserName string `json:"user_name"` // 用户名称

	ShareTime int64 `json:"share_time"`

	Status int `json:"status"`

	Photo string `json:"photo"` // 照片

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`

	AcceptedAt int64 `json:"accepted_at"` // 接受时间
}

// ShareEbikeDeleteRequest 删除现场数据
type ShareEbikeDeleteRequest struct {
	Id int64 `json:"id" binding:"required"`
}

type ShareEbikeBaseRequest struct {
	Id int64 `json:"id" binding:"required"`
}

// ShareEbikesEntityToDto entity数据转换
func ShareEbikesEntityToDto(shareEbikes []*entity.ShareEbike) []*ShareEbikeInfo {
	out := make([]*ShareEbikeInfo, 0, len(shareEbikes))
	for _, c := range shareEbikes {
		out = append(out, ShareEbikeEntityToDto(c))
	}
	return out
}

// ShareEbikeEntityToDto entity数据转换
func ShareEbikeEntityToDto(e *entity.ShareEbike) *ShareEbikeInfo {
	return &ShareEbikeInfo{

		Id: e.Id,

		UserId: e.UserId,

		EbikeId: e.EbikeId,

		ShareUserId: e.ShareUserId,

		Phone: e.Phone,

		Photo: e.Photo,

		Name: e.Name,

		ShareTime: e.ShareTime,

		Status: e.Status,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,

		AcceptedAt: e.AcceptedAt,
	}
}
